package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.ScilabExecute;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.osa.lab.ScilabSetting;

@LabUiAnnotation(caption="Scilab")
public class ScilabWrapper extends Calculator {
	public static final String INPUT1 = "data1";
	public static final String INPUT2 = "data2";
	public static final String OUTPUT1 = "ret";
	private ScilabSetting setting;
	
	
	public ScilabWrapper(ScilabSetting setting) {
		this.setting = setting;
		initInput(INPUT1);
		initInput(INPUT2);
		initOutput(OUTPUT1);
	}
	
	@Override
	public synchronized void process() {	
		ComplexArray out = null;

		ComplexArray in1 = this.getInput(INPUT1);
		ComplexArray in2= this.getInput(INPUT2);
		
		
		if (in1 == null && in2 == null) {
			out = ScilabExecute.execute(setting.getCommand(), "ret");
		}
		else if (in1 != null && in2 == null) {
			out = ScilabExecute.execute(setting.getCommand(), in1, "ret");
		}
		else {
			
			out = ScilabExecute.execute(setting.getCommand(), in1, in2, "ret");
		} 
		this.setOutput(OUTPUT1, out);
	}

	@Override
	public Object getSetting() {
		return this.setting;
	}

}
